package com.gxpt.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gxpt.app.AppUtils;
import com.gxpt.app.Constant;
import com.gxpt.app.R;
import com.gxpt.app.base.ListBaseAdapter;
import com.gxpt.app.base.SuperViewHolder;
import com.gxpt.app.bean.applylist_bean;
import com.gxpt.app.bean.orderlist_bean;
import com.utils.ScreenUtils;
import com.utils.picasso.PicassoUtils;

import java.util.List;

/**
 * Created by Lzx on 2016/12/30.
 */

public class shopping_applylist_list_Adapter extends ListBaseAdapter<applylist_bean.applylist> {

    //列表图片
    int pic_view_width = 0;
    int pic_view_hight = 0;
    Context context;

    public shopping_applylist_list_Adapter(Context context) {
        super(context);
        this.context = context;
        int Sviewwidth  = ScreenUtils.getScreenWidth(context);//
        pic_view_width  = Sviewwidth / 4;
        pic_view_hight  = pic_view_width/10*9;

    }

    @Override
    public int getLayoutId() {
        return R.layout.item_shopping_applylist_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        applylist_bean.applylist item = mDataList.get(position);

        applylist_bean.applylist.order_info_ap order_info_ap_data = item.order_info;

        TextView txt_status = holder.getView(R.id.txt_status);
        txt_status.setText(AppUtils.getApplySTUTS(Integer.parseInt(item.status)));

        TextView txt_has_pay = holder.getView(R.id.txt_has_pay);
        txt_has_pay.setText(context.getResources().getString(R.string.f_1)+order_info_ap_data.has_pay);

        TextView txt_refund_pay = holder.getView(R.id.txt_refund_pay);
        txt_refund_pay.setText(context.getResources().getString(R.string.f_1)+order_info_ap_data.refund_pay);

        TextView txt_service_id = holder.getView(R.id.txt_service_id);
        txt_service_id.setText(item.service_id);



        LinearLayout layout_sub = holder.getView(R.id.layout_sub);
        layout_sub.removeAllViews();
        List<applylist_bean.applylist.goods_info_ap> goods = item.goods_info;


        if(goods != null ){
            if(goods.size()>0){
                for (int a = 0; a < goods.size(); a++) {
                    layout_sub.addView(creatListItemView(goods.get(a)));
                }
            }
        }
    }

    private View creatListItemView(applylist_bean.applylist.goods_info_ap d) {
        View convertView = LayoutInflater.from(context).inflate(R.layout.item_item_shopping_applylist_list, null);

        ImageView img_thumb= (ImageView)convertView.findViewById(R.id.img_thumb);
        if(d.thumb.isEmpty()){
            PicassoUtils.Picasso_displayImage(context,R.mipmap.ic_launcher,pic_view_width,pic_view_hight,img_thumb);
        }else{
            PicassoUtils.Picasso_displayImage(context, Constant.IP +d.thumb,pic_view_width,pic_view_hight,img_thumb);
        }

        TextView txt_goods_name = (TextView)convertView.findViewById(R.id.txt_goods_name);
        txt_goods_name.setText(d.goods_name);

        TextView txt_sku_name = (TextView)convertView.findViewById(R.id.txt_sku_name);
        txt_sku_name.setText(d.sku_name);

        TextView txt_sell_price = (TextView)convertView.findViewById(R.id.txt_sell_price);
        txt_sell_price.append(""+d.sell_price);


        TextView txt_buy_num = (TextView)convertView.findViewById(R.id.txt_buy_num);
        txt_buy_num.setText("x "+d.goods_num);

        return convertView;
    }

}
